package com.example.im.ui.activity

import android.content.Intent
import android.text.Editable
import android.view.View
import com.example.im.R
import com.google.android.material.snackbar.Snackbar
import com.example.im.mvp.presenter.AccessPresenter
import com.example.im.mvp.view.IAccessView
import com.example.im.ui.abstracts.AbstractBaseActivity
import com.example.im.utils.LogUtils
import com.example.im.utils.RandomUntil
import kotlinx.android.synthetic.main.activity_access.*

class AccessActivity : AbstractBaseActivity<AccessPresenter>(), IAccessView {

    override val layoutId: Int
        get() = R.layout.activity_access

    override fun initView() {

    }

    override fun initPresenter() {
        mPresenter = AccessPresenter((this), (this))
    }

    fun onClick(view: View) {
        when (view.id) {
            R.id.tv_in_user_login -> {
                mPresenter!!.userSignIn(
                    et_in_user_name.text.toString(),
                    et_in_user_pwd.text.toString()
                )
            }
            R.id.tv_in_to_on -> {
                linear_login.visibility = View.GONE
                linear_logon.visibility = View.VISIBLE
            }
            R.id.tv_on_user_logon -> {
                mPresenter!!.userSignUp(
                    et_on_user_name.text.toString(),
                    et_on_user_pwd.text.toString(),
                    et_on_user_invite.text.toString()
                )
            }
            R.id.tv_on_to_in -> {
                linear_logon.visibility = View.GONE
                linear_login.visibility = View.VISIBLE
            }
            R.id.tv_user_go_login -> {
                linear_invite.visibility = View.GONE
                linear_logon.visibility = View.GONE
                linear_login.visibility = View.VISIBLE
            }
        }
    }

    override fun onLoginSuccess() {
        startActivity(Intent((this), MainActivity::class.java))
        finish()
    }

    override fun onLogonSuccess(account: String) {
        linear_logon.visibility = View.GONE
        linear_login.visibility = View.GONE
        linear_invite.visibility = View.VISIBLE
        tv_user_account.text = account
        et_in_user_name.text = Editable.Factory.getInstance().newEditable(account)
    }
}